﻿using System;
using System.Collections.Generic;
using Sok.Munkae.Util;

namespace Sok.Munkae.Tenant
{
    public class HostNameIdentifier : ITenantIdentifier
    {
        private string organizationShortName;
        private IHostNameProvider hostNameProvider;
        private SQLHelper SqlHelper;

        public HostNameIdentifier(IHostNameProvider hostNameProvider)
        {
            SqlHelper = new SQLHelper();
            this.hostNameProvider = hostNameProvider;
        }

        #region ITenantIdentifier Members

        public ITenant GetTenant()
        {
            throw new NotImplementedException();
        }

        public int GetTenantId()
        {
            this.organizationShortName = hostNameProvider.GetHostName();
            string sql = "select Id from Organization WHERE ShortName = @ShortName";
            int Id = 0;
            Id = (int) SqlHelper.ExecuteScalar(sql,
                                               new Dictionary<string, object>
                                                   {{"@ShortName", organizationShortName}});
            return Id;
        }

        #endregion
    }

    public interface IHostNameProvider
    {
        string GetHostName();
        string GetDomainName();
    }
}